package com.jt.controller;

import com.jt.service.FileService;
import com.jt.vo.ImageVO;
import com.jt.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

@RestController
@CrossOrigin
@RequestMapping("/file")
public class FileController {
    @Autowired
    private FileService fileService;

    @PostMapping("/upload")
    public SysResult upload2(MultipartFile file){
        ImageVO imageVO = fileService.upload(file);
        return SysResult.success(imageVO);
    }
    @DeleteMapping("/deleteFile")
    public SysResult deleteFile(String virtualPath){
        fileService.deleteFile(virtualPath);
        return SysResult.success();
    }

//    @PostMapping("/upload")
//    public SysResult upload(MultipartFile file) throws IOException {
//        String filename = file.getOriginalFilename();//获取图片的名称
//        String fileDir = "E:/images";//封装文件上传目录
//        File dir = new File(fileDir);
//        if(!dir.exists()){//如果目录不存在，则创建目录
//            dir.mkdirs();
//        }
//        String path = fileDir + "/" +filename;//封装文件的全路径
//        file.transferTo(new File(path));//上传文件
//        return SysResult.success();
//    }
}
